package org.rabbitmq.test7;

import com.rabbitmq.client.Channel;
import org.rabbitmq.utils.RabbitMqUtils;

import java.util.HashMap;
import java.util.Map;

public class EmitLogTopic {
    public static final String EXCHANGE_NAME = "topic_logs";
    public static void main(String[] args) throws Exception {
//        获取信道
        Channel channel = RabbitMqUtils.getChannel();
        //
        Map<String,String> bindingKeyMAp = new HashMap<>();
        bindingKeyMAp.put("quick.orange.rabbit","被队列 Q1Q2 接收到");
        bindingKeyMAp.put("lazy.orange.elephant","被队列 Q1Q2 接收到");
        bindingKeyMAp.put("quick.orange.fox","被队列 Q1 接收到");
        bindingKeyMAp.put("lazy.brown.fox","被队列 Q2 接收到");
        bindingKeyMAp.put("lazy.pink.rabbit","虽然满足两个绑定但只被队列 Q2 接收一次");
        bindingKeyMAp.put("quick.brown.fox","不匹配任何绑定不会被任何队列接收到会被丢弃");
        bindingKeyMAp.put("quick.orange.male.rabbit",".rabbit 是四个单词不匹配任何绑定会被丢弃");
        bindingKeyMAp.put("lazy.orange.male.rabbit",".rabbit 是四个单词但匹配");

        for (Map.Entry<String,String> stringStringEntry : bindingKeyMAp.entrySet()){
            String key = stringStringEntry.getKey();
            String message = stringStringEntry.getValue();
            channel.basicPublish(EXCHANGE_NAME,key,null,message.getBytes("UTF-8"));
            System.out.println("发送消息："+message);
        }
    }
}
